<?php

use yii\db\Migration;

/**
 * Handles the creation of table `{{%fond_item}}`.
 * Has foreign keys to the tables:
 *
 * - `{{%fond_collection}}`
 */
class m231204_073114_create_fond_item_table extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
        $this->createTable('{{%fond_item}}', [
            'id' => $this->primaryKey(),
            'title' => $this->string()->notNull(),
            'short_description' => $this->string(1024),
            'full_description' => $this->text(),
            'tabular_data' => $this->text(),
            'prev_img' => $this->string(45),
            'gallery_img' => $this->string(255),
            'id_fond_collection' => $this->integer()->notNull(),
        ]);

        // creates index for column `id_fond_collection`
        $this->createIndex(
            '{{%idx-fond_item-id_fond_collection}}',
            '{{%fond_item}}',
            'id_fond_collection'
        );

        // add foreign key for table `{{%fond_collection}}`
        $this->addForeignKey(
            '{{%fk-fond_item-id_fond_collection}}',
            '{{%fond_item}}',
            'id_fond_collection',
            '{{%fond_collection}}',
            'id',
            'CASCADE'
        );
    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        // drops foreign key for table `{{%fond_collection}}`
        $this->dropForeignKey(
            '{{%fk-fond_item-id_fond_collection}}',
            '{{%fond_item}}'
        );

        // drops index for column `id_fond_collection`
        $this->dropIndex(
            '{{%idx-fond_item-id_fond_collection}}',
            '{{%fond_item}}'
        );

        $this->dropTable('{{%fond_item}}');
    }
}
